package cn.tedu.property_management_system.controller;

import cn.tedu.property_management_system.entity.CarUser;
import cn.tedu.property_management_system.mapper.CarMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/parking")
public class CarController {
    @Autowired
    CarMapper carMapper;
    @RequestMapping("search/select")
    public List<CarUser> select(){
        System.out.println(carMapper.select());
        return carMapper.select();
    }
    @RequestMapping("select")
    public List<CarUser> search(@RequestBody CarUser carUser) {
        return carMapper.searchSelect(carUser);
    }
    @RequestMapping("count/select")
    public int count() {
        return carMapper.countSelect();
    }
    @RequestMapping("selects")
    public List<CarUser> searchs(@RequestBody CarUser carUser) {
        return carMapper.searchSelects(carUser);
    }
    @RequestMapping("add/insert")
    public void insert(@RequestBody CarUser carUser){
        carMapper.insert(carUser);
    }
    @RequestMapping("edit/update")
    public void update(@RequestBody CarUser carUser){
        carMapper.update(carUser);
    }
    @RequestMapping("user/delete")
    public void delete(@RequestBody CarUser carUser){
        carMapper.delete(carUser.getId());
    }
    @RequestMapping("users/delete")
    public int deletes(@RequestBody List<CarUser> list){

        if (list.size()>0) {
            for (CarUser carUser : list) {
                carMapper.delete(carUser.getId());
            }
            return 1;
        }else {
            return 2;
        }
    }
}
